<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="优惠券名称" prop="couponsName">
        <el-input
          v-model="queryParams.couponsName"
          placeholder="请输入优惠券名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['coupons:coupons:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['coupons:coupons:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['coupons:coupons:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['coupons:coupons:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="couponsList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="优惠券id" align="center" prop="id" />
      <el-table-column label="优惠券名称" align="center" prop="couponsName" />
      <el-table-column label="优惠券类型" align="center" prop="couponsType" >
        <template slot-scope="scope">
          {{scope.row.couponsType==1?'通用券':scope.row.couponsType==2?'品类券':'商品券'}}
        </template>
      </el-table-column>
      <el-table-column label="优惠券面值" align="center" prop="faceValue" />
      <el-table-column label="领取方式" align="center" prop="sendType" >
        <template slot-scope="scope">
          {{scope.row.sendType==1?'手动领取':scope.row.sendType==2?'新人券':scope.row.sendType==3?'系统赠送':'付费会员专享'}}
        </template>
      </el-table-column>
      <el-table-column label="领取日期" align="center" prop="receive" >
        <template slot-scope="scope" >
          {{scope.row.receive==2?'不限时':(scope.row.receiveStatrTime+'--'+scope.row.receiveEndTime)}}
        </template>
      </el-table-column>
      <el-table-column label="使用时间" align="center" prop="useTime" >
          <template slot-scope="scope">
            <div v-if="scope.row.useTime==2">
              <span>{{ parseTime(scope.row.useStartTime, '{y}-{m}-{d}') }}</span>
              <br>
              <span>{{ parseTime(scope.row.useEndTime, '{y}-{m}-{d}') }}</span>
            </div>
            <div v-if="scope.row.useTime==1">
              <span>{{ scope.row.useDays }}天</span>
            </div>
          </template>
      </el-table-column>
      <el-table-column label="发布数量" align="center" prop="releases" >
        <template slot-scope="scope" >
          {{scope.row.releases==2?'不限量':scope.row.releasesNum}}
        </template>
      </el-table-column>
      <el-table-column label="优惠券状态" align="center" prop="couponsStatus" >
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.couponsStatus"
            active-color="#13ce66"
            active-text="正常"
            inactive-text="未开启"
            inactive-color="#ff4949"
            :active-value="1"
            :inactive-value="0">
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['coupons:coupons:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleCopy(scope.row)"
            v-hasPermi="['coupons:coupons:edit']"
          >复制</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['coupons:coupons:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!--  复制优惠券列表对话框-->
    <el-dialog :title="title" :visible.sync="openCope" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="优惠券名称" prop="couponsName">
          <el-input v-model="form.couponsName" placeholder="请输入优惠券名称" />
        </el-form-item>
        <el-form-item label="优惠券面值" prop="faceValue">
          <el-input v-model="form.faceValue" placeholder="请输入优惠券面值" />
        </el-form-item>
        <el-form-item label="发送方式">
          <el-radio-group v-model="form.sendType">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">用户领取</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">新用户自动发放</el-radio>
            <el-radio :label="3" v-if="title=='复制优惠券列表'">系统赠送</el-radio>
            <el-radio :label="4" v-if="title=='复制优惠券列表'">付费会员专享</el-radio>
          </el-radio-group><br>
          <span>用户领取：用户需要手动领取优惠券；</span><br>
          <span>新用户自动发放：新注册的用户自动发放；</span><br>
          <span>系统赠送：后台发放指定用户或者添加到商品里面用户购买该商品获得；</span><br>
          <span>付费会员专享：仅付费会员可以领取和使用</span>
        </el-form-item>
        <el-form-item label="优惠卷类型">
          <el-radio-group v-model="form.couponsType">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">通用卷</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">品类卷</el-radio>
            <el-radio :label="3" v-if="title=='复制优惠券列表'">商品卷</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="商品类型" v-if="form.couponsType==2">
          <el-select v-model="form.productId" placeholder="请选择">
            <el-option
              v-for="item in productList"
              :key="item.id"
              :label="item.productName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <!--        <el-form-item label="商品名称id" prop="productId">-->
        <!--          <el-input v-model="form.productId" placeholder="请输入商品名称id" />-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="商品分类名称id" prop="categoryId">-->
        <!--          <el-input v-model="form.categoryId" placeholder="请输入商品分类名称id" />-->
        <!--        </el-form-item>-->
        <el-form-item label="使用门槛">
          <el-radio-group v-model="form.useDoorsill">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">无门槛</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">有门槛</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="useMoney" v-if="form.useDoorsill==2 && title=='复制优惠券列表'">
          <el-input v-model="form.useMoney"  placeholder="请输入最低消费" />
          <span>填写优惠劵的最低消费金额</span>
        </el-form-item>
        <el-form-item label="使用时间">
          <el-radio-group v-model="form.useTime">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">天数</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">时间段</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="useDays" v-if="form.useTime==1 && title=='复制优惠券列表'">
          <el-input v-model="form.useDays" placeholder="请输入" />
          <span>领取后多少天内有效</span>
        </el-form-item>
        <el-form-item label="开始时间段" prop="time" v-if="form.useTime==2 && title=='复制优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useStartTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间段" prop="useEndTime" v-if="form.useTime==2 && title=='复制优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useStartTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取时间" v-if="form.sendType==1 || form.sendType==4 ">
          <el-radio-group v-model="form.receive">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">限时</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">不限时</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="领取开始时间" prop="receiveStatrTime" v-if="form.receive==1 && title=='复制优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveStatrTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取结束时间" prop="receiveEndTime" v-if="form.receive==1 && title=='复制优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveEndTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="优惠卷发布数量" v-if="form.sendType==1 || form.sendType==4">
          <el-radio-group v-model="form.releases">
            <el-radio :label="1" v-if="title=='复制优惠券列表'">限量</el-radio>
            <el-radio :label="2" v-if="title=='复制优惠券列表'">不限量</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="releasesNum" v-if="form.releases==1">
          <el-input v-model="form.releasesNum" placeholder="请输入数量" />
          <span>填写优惠劵的发布数量</span>
        </el-form-item>
        <el-form-item label="用户领取数量" prop="userGetNum" v-if="form.releases==1 || form.releases==2">
          <el-input v-model="form.userGetNum" placeholder="请输入用户领取数量" />
          <span>填写每个用户可以领取多少张</span>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.couponsStatus">
            <el-radio :label="1">开启</el-radio>
            <el-radio :label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改优惠券列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="优惠券名称" prop="couponsName">
          <el-input v-model="form.couponsName" placeholder="请输入优惠券名称" />
        </el-form-item>
        <el-form-item label="优惠券面值" prop="faceValue">
          <el-input v-model="form.faceValue" placeholder="请输入优惠券面值" />
        </el-form-item>
        <el-form-item label="发送方式">
          <el-radio-group v-model="form.sendType">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">用户领取</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">新用户自动发放</el-radio>
            <el-radio :label="3" v-if="title=='添加优惠券列表'">系统赠送</el-radio>
            <el-radio :label="4" v-if="title=='添加优惠券列表'">付费会员专享</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.sendType==1)">用户领取</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.sendType==2)">新用户自动发放</el-radio>
            <el-radio :label="3" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.sendType==3)">系统赠送</el-radio>
            <el-radio :label="4" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.sendType==4)">付 费会员专享</el-radio>
          </el-radio-group><br>
          <span>用户领取：用户需要手动领取优惠券；</span><br>
          <span>新用户自动发放：新注册的用户自动发放；</span><br>
          <span>系统赠送：后台发放指定用户或者添加到商品里面用户购买该商品获得；</span><br>
          <span>付费会员专享：仅付费会员可以领取和使用</span>
        </el-form-item>
        <el-form-item label="优惠卷类型">
          <el-radio-group v-model="form.couponsType">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">通用卷</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">品类卷</el-radio>
            <el-radio :label="3" v-if="title=='添加优惠券列表'">商品卷</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.couponsType==1)">通用卷</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.couponsType==2)">品类卷</el-radio>
            <el-radio :label="3" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.couponsType==3)">商品卷</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="商品类型" v-if="form.couponsType==2">
          <el-select v-model="form.productId" placeholder="请选择">
            <el-option
              v-for="item in productList"
              :key="item.id"
              :label="item.productName"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
<!--        <el-form-item label="商品名称id" prop="productId">-->
<!--          <el-input v-model="form.productId" placeholder="请输入商品名称id" />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="商品分类名称id" prop="categoryId">-->
<!--          <el-input v-model="form.categoryId" placeholder="请输入商品分类名称id" />-->
<!--        </el-form-item>-->
        <el-form-item label="使用门槛">
          <el-radio-group v-model="form.useDoorsill">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">无门槛</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">有门槛</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.useDoorsill==1)">无门槛</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.useDoorsill==2)" >有门槛</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="useMoney" v-if="form.useDoorsill==2 && title=='添加优惠券列表'">
          <el-input v-model="form.useMoney"  placeholder="请输入最低消费" />
          <span>填写优惠劵的最低消费金额</span>
        </el-form-item>
        <el-form-item label="" prop="useMoney" v-if="form.useDoorsill==2 && title=='修改优惠券列表'">
          <el-input v-model="form.useMoney" :disabled="true"  placeholder="请输入最低消费" />
          <span>填写优惠劵的最低消费金额</span>
        </el-form-item>
        <el-form-item label="使用时间">
          <el-radio-group v-model="form.useTime">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">天数</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">时间段</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.useTime==1)">天数</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.useTime==2)">时间段</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="useDays" v-if="form.useTime==1 && title=='添加优惠券列表'">
          <el-input v-model="form.useDays" placeholder="请输入" />
          <span>领取后多少天内有效</span>
        </el-form-item>
        <el-form-item label="" prop="useDays" v-if="form.useTime==1 && title=='修改优惠券列表'">
          <el-input v-model="form.useDays" :disabled="true" placeholder="请输入" />
          <span>领取后多少天内有效</span>
        </el-form-item>
        <el-form-item label="开始时间段" prop="useStartTime" v-if="form.useTime==2 && title=='添加优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useStartTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="开始时间段" prop="useStartTime" v-if="form.useTime==2 && title=='修改优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useStartTime"
                          type="date"
                          disabled
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间段" prop="useEndTime" v-if="form.useTime==2 && title=='添加优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useEndTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束时间段" prop="useEndTime" v-if="form.useTime==2 && title=='修改优惠券列表'">
          <el-date-picker clearable
                          v-model="form.useEndTime"
                          type="date"
                          disabled
                          value-format="yyyy-MM-dd"
                          placeholder="请选择">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取时间" v-if="form.sendType==1 || form.sendType==4 ">
          <el-radio-group v-model="form.receive">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">限时</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">不限时</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.receive==1)">限时</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.receive==2)">不限时</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="领取开始时间" prop="receiveStatrTime" v-if="form.receive==1 && title=='添加优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveStatrTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取开始时间" prop="receiveStatrTime" v-if="form.receive==1 && title=='修改优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveStatrTime"
                          type="date"
                          disabled
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取结束时间" prop="receiveEndTime" v-if="form.receive==1 && title=='添加优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveEndTime"
                          type="date"
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领取结束时间" prop="receiveEndTime" v-if="form.receive==1 && title=='修改优惠券列表'">
          <el-date-picker clearable
                          v-model="form.receiveEndTime"
                          type="date"
                          disabled
                          value-format="yyyy-MM-dd"
                          placeholder="请选择输入时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="优惠卷发布数量" v-if="form.sendType==1 || form.sendType==4">
          <el-radio-group v-model="form.releases">
            <el-radio :label="1" v-if="title=='添加优惠券列表'">限量</el-radio>
            <el-radio :label="2" v-if="title=='添加优惠券列表'">不限量</el-radio>
            <el-radio :label="1" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.releases==1)">限量</el-radio>
            <el-radio :label="2" v-if="title=='修改优惠券列表'" :disabled="!(title=='修改优惠券列表'&&form.releases==2)">不限量</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="" prop="releasesNum" v-if="form.releases==1">
          <el-input v-model="form.releasesNum" placeholder="请输入数量" />
          <span>填写优惠劵的发布数量</span>
        </el-form-item>
        <el-form-item label="用户领取数量" prop="userGetNum" v-if="form.releases==1 || form.releases==2">
          <el-input v-model="form.userGetNum" placeholder="请输入用户领取数量" />
          <span>填写每个用户可以领取多少张</span>
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.couponsStatus">
            <el-radio :label="1">开启</el-radio>
            <el-radio :label="2">关闭</el-radio>
          </el-radio-group>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCoupons, getCoupons, delCoupons, addCoupons, updateCoupons } from "@/api/coupons/index";
import { listComments, getComments, delComments, addComments, updateComments,productList } from "@/api/comments/comments";
export default {
  name: "Coupons",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      openCope:false,
      num:null,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 优惠券列表表格数据
      couponsList: [],
      // 弹出层标题
      title: "",
      productList:[],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        couponsName: null,
        faceValue: null,
        sendType: null,
        couponsType: null,
        productId: null,
        categoryId: null,
        useDoorsill: null,
        useMoney: null,
        useTime: null,
        useDays: null,
        useStartTime: null,
        useEndTime: null,
        receive: null,
        receiveStatrTime: null,
        receiveEndTime: null,
        releases: null,
        releasesNum: null,
        couponsStatus: null,
        userGetNum: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
    this.productListSelect();
  },
  methods: {
    productListSelect(){
      productList().then(res=>{
        this.productList=res;
      })
    },
    /** 查询优惠券列表列表 */
    getList() {
      this.loading = true;
      listCoupons(this.queryParams).then(response => {
        this.couponsList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openCope=false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        couponsName: null,
        faceValue: null,
        sendType: null,
        couponsType: null,
        productId: null,
        categoryId: null,
        useDoorsill: null,
        useMoney: null,
        useTime: null,
        useDays: null,
        useStartTime: null,
        useEndTime: null,
        receive: null,
        receiveStatrTime: null,
        receiveEndTime: null,
        releases: null,
        releasesNum: null,
        couponsStatus: null,
        userGetNum: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.form={};
      this.open = true;
      this.title = "添加优惠券列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.form={};
      const id = row.id || this.ids
      getCoupons(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改优惠券列表";
      });
    },
    // 复制按钮操作
    handleCopy(row){
      this.reset();
      const id = row.id || this.ids
      getCoupons(id).then(response => {
        this.form = response.data;
        this.form.id=null
        this.openCope = true;
        this.title = "复制优惠券列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCoupons(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCoupons(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
      this.open=true;
      this.open=false;
      this.openCope=false;
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除优惠券列表编号为"' + ids + '"的数据项？').then(function() {
        return delCoupons(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('coupons/coupons/export', {
        ...this.queryParams
      }, `coupons_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
